﻿var serverIP = "ws://192.168.1.22:8080/";
var filePath = getRootPath() + "/uploads/";
function getRootPath() {
    var strFullPath = window.document.location.href;
    var strPath = window.document.location.pathname;
    var pos = strFullPath.indexOf(strPath);
    var prePath = strFullPath.substring(0, pos);
    var postPath = strPath.substring(0, strPath.substr(1).indexOf('/') + 1);
    return (prePath + postPath);
}


//正确函数
function snackbar(msg) {
    var content = $('<div class="snackbar el-message">' + msg + '</div>');
    if ($('.snackbar').length < 1) {
        content.appendTo($('body'));
        content.animate({
            top: 50,
            opacity: 1,


        },
          600, function () {
              /* stuff to do after animation is complete */
              content.delay(1500).fadeOut(500, function () {
                  $(this).remove();
              });
          });
    } else {
        $('.snackbar').not($(this)).remove();
        content.appendTo($('body'));
        content.animate({
            top: 50,
            opacity: 1
        },
          600, function () {
              /* stuff to do after animation is complete */
              content.delay(1000).fadeOut(500, function () {
                  $(this).remove();
              });
          });
    }

}
//错误提示函数
function errorSnackbar(msg) {
    var content = $('<div class="errorbar el-message">' + msg + '</div>');
    if ($('.snackbar').length < 1) {
        content.appendTo($('body'));
        content.animate({
            top: 50,
            //opacity: .8
        },
          600, function () {
              /* stuff to do after animation is complete */
              content.delay(2000).fadeOut(500, function () {
                  $(this).remove();
              });
          });
    } else {
        $('.snackbar').not($(this)).remove();
        content.appendTo($('body'));
        content.animate({
            top: 50,
            // opacity: .8
        },
          600, function () {
              /* stuff to do after animation is complete */
              content.delay(1000).fadeOut(500, function () {
                  $(this).remove();
              });
          });
    }

}

var countdown = 60;
function settime(elmt, text) { //璁剧疆鍊掕鏃�
    if (countdown == 0) {
        $(elmt).html(text);
        $(elmt).removeAttr('disabled');
        countdown = 60;
        return false;
    } else {
        $(elmt).attr('disabled', 'disabled');
        $(elmt).html("(" + countdown + ") 宸插彂閫�");
        countdown--;
    }
    setTimeout(function () {
        settime(elmt, text);
    }, 1000)
}
document.onkeydown = function (event) {
    var e = event || window.event || arguments.callee.caller.arguments[0];
    if (e && e.keyCode == 27) { // 按 Esc 
        //要做的事情
    }
    if (e && e.keyCode == 113) { // 按 F2 
        //要做的事情
    }
    if (e && e.keyCode == 13) { // enter 键
        //要做的事情
    }
};
/*
 * 格式化参数
 */
function formatterParameter(obj) {
    return obj;
}

/**
 * Json转对象
 * @param {} data 
 * @returns {} 
 */
function JsonPar(data) {
    return eval('(' + data + ')');
}



var convertDateFunc = function (jsondate) {
    if (jsondate != "" && jsondate != null) {
        jsondate = jsondate.replace("/Date(", "").replace(")/", "");
        if (jsondate.indexOf("+") > 0) {
            jsondate = jsondate.substring(0, jsondate.indexOf("+"));
        } else if (jsondate.indexOf("-") > 0) {
            jsondate = jsondate.substring(0, jsondate.indexOf("-"));
        }
        var date = new Date(parseInt(jsondate, 10));
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
        var second = date.getMilliseconds() / 1000 < 10 ? "0" + parseInt(date.getMilliseconds() / 1000) : parseInt(date.getMilliseconds() / 1000);
        return date.getFullYear() + "-" + month + "-" + currentDate + " " + hours + ":" + minutes + ":" + second
    } else {
        return "";
    }
};


function getCookie(name) {
    if (name == "u_name") {
        return "JackerKun";
    }
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg)) {
        return unescape(arr[2]);
    } else {
        return null;
    }
}


function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
    var expires = "expires=" + d.toUTCString();
    document.cookie = cname + "=" + cvalue + "; " + expires;
}

function delCookie(name) {
}


/*
 * 获取浏览器Get参数
 */
function getQueryString无法Decode(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}

/**
 * 请求参数获取
 * @param {} name 
 * @returns {} 
 */
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = decodeURI(window.location.search).substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}
